﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DecisionFramework.Result
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.Serialization;

    namespace DecisionFramework.Result
    {
        /// <summary>
        /// Represents the result of a service call. 
        /// </summary>
        /// <remarks>  
        /// It can either be a data member of another result object or extended.
        /// <para></para>
        /// Author: Greg Cowin 
        /// </remarks> 
        [DataContract]
        public class ServiceResult
        {
            /// <summary>
            /// The result status: Success, Failure, ServiceUnavailable, NotAuthorized, SecurityTokenExpired, InvalidSecurityToken, RuleViolation, or Extended.
            /// </summary>
            [DataMember]
            public ServiceResultStatus ServiceResultStatus { get; set; }

            /// <summary>
            /// An optional property name can be used to narrow validation rule
            /// violation down to a single property.
            /// </summary>
            [DataMember]
            public string PropertyName { get; set; }

            /// <summary>
            /// Reasoning of a non success status.
            /// </summary>
            [DataMember]
            public string Reason { get; set; }

            /// <summary>
            /// Services can add an extended status.
            /// </summary>
            [DataMember]
            public int ExtentedStatus { get; set; }

            /// <summary>
            /// Whether the state is success.
            /// </summary>
            /// <returns>Whether the state is success.</returns>
            public bool IsSuccess()
            {
                return ServiceResultStatus == ServiceResultStatus.Success;
            }
        }
    }

}
